package com.caojing.haolemai.ui.outlets.outletsdetail;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.caojing.haolemai.bean.outletsdetailsbean.OutletsDeatailsBean;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/10/20 0020.
 */
public class OutletsDetailPresenter implements OutletsDetailContract.Presenter{
    private OutletsDetailContract.View view;
    private OutletsDetailContract.Model model;

    public OutletsDetailPresenter(OutletsDetailContract.View view){
        this.view=view;
        this.model=new OutletsDetailModel();
    }


    @Override
    public void getVertical(String id, String pager, Map<String, String> params) {
       model.getResultsBean(id, pager, params, new Callback<OutletsDeatailsBean>() {
           @Override
           public void onResponse(Call<OutletsDeatailsBean> call, Response<OutletsDeatailsBean> response) {
               final OutletsDeatailsBean outletsDeatailsBean=response.body();
               Handler handler=new Handler(Looper.getMainLooper());
               handler.post(new Runnable() {
                   @Override
                   public void run() {
                       if (outletsDeatailsBean!=null){

                           view.onGetDetailBeanSucess(outletsDeatailsBean);
                       }
                   }
               });
           }

           @Override
           public void onFailure(Call<OutletsDeatailsBean> call, Throwable t) {
               Log.i("tag",t.getMessage()+"加载数据失败");
               view.onGetDetailBeanFail(t.getMessage());
           }
       });




    }
}
